package com.chefu.order.controller;


import com.chefu.common.pojo.PageResult;
import com.chefu.common.pojo.R;
import com.chefu.order.pojo.vo.ServerOrderDetailVo;
import com.chefu.order.pojo.vo.ServerOrderPageParamVo;
import com.chefu.order.pojo.vo.ServerOrderPageVo;
import com.chefu.order.service.ServerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author goodgoodstudy
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/order/server")
public class ServerOrderController {

    @Autowired
    private ServerOrderService serverOrderService;

    /**
     * 通过分页和查询条件，获取服务订单列表
     * @param pageNo 当前页
     * @param pageSize 页面大小
     * @param paramVo 查询参数
     * @return 服务订单列表
     */
    @GetMapping("/page")
    public R getOrderPage(@RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo,
                          @RequestParam(value = "pageSize",defaultValue = "20")Integer pageSize,
                          @Valid ServerOrderPageParamVo paramVo
                          ){
        PageResult<ServerOrderPageVo> pageResult = serverOrderService.getOrderPage(pageNo,pageSize,paramVo);
        return R.ok().data("pageResult",pageResult);
    }

    @GetMapping("/page/pending")
    public R getPendingServerOrder(@RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo,
                                     @RequestParam(value = "pageSize",defaultValue = "20")Integer pageSize,
                                     @Valid ServerOrderPageParamVo paramVo
                                     ){
        PageResult<ServerOrderPageVo> pageResult = serverOrderService.getPendingServerOrder(pageNo,pageSize,paramVo);
        return R.ok().data("pageResult",pageResult);
    }

    @PutMapping("/page/close")
    public R closeServerOrder(@RequestParam("orderId")Long orderId){
        serverOrderService.closeServerOrder(orderId);
        return R.ok();
    }

    @PutMapping("/{orderId}")
    public R getOrderDetail(@PathVariable("orderId")Long orderId){
        ServerOrderDetailVo serverOrderVo =  serverOrderService.getOrderDetail(orderId);
        return R.ok().data("serverOrderVo",serverOrderService);
    }
}

